package com.craney.testTextField
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class TestTextField extends Sprite
	{
		private var parentSprite:Sprite;
		private var txt:TextField;
		public function TestTextField(ps:Sprite)
		{
			this.graphics.beginFill(0xaaaaaa);
			this.graphics.drawRoundRect(100, 100, 30, 100, 10);
			this.graphics.endFill();
			
			ps.graphics.lineTo(10, 10);
			ps.graphics.lineTo(510, 10);
			ps.graphics.lineTo(510, 510);
			ps.graphics.lineTo(10, 510);
			
			parentSprite = ps;
			txt = new TextField();
			txt.text = "JioJio!";
			txt.border = true;
			txt.background = true;
			txt.backgroundColor = 0x666666;
			txt.autoSize = TextFieldAutoSize.CENTER;
			
//			txt.htmlText = "<u><a href='event:geturl|http://www.tudou.com'>here</a></u>";
			txt.htmlText = "<i><b><font size='60'>big</font></b></i>";

			addEventListener(MouseEvent.MOUSE_DOWN, down);
			addEventListener(MouseEvent.MOUSE_UP, up);
			txt.addEventListener(TextEvent.LINK, clickLink);
			
			addChild(txt);
			this.rotation = 90;
			parentSprite.addChild(this);
		}
		
		private function clickLink(event:TextEvent):void
		{
			var cmdArray:Array = event.text.split("|");
			navigateToURL(new URLRequest(cmdArray[1]), cmdArray[2]);
		}
		
		private function down(event:Event):void
		{
			trace("start");
			var sprit:Sprite = txt.parent as Sprite;
			this.startDrag();
		}
		
		private function up(event:Event):void
		{
			trace("end");
			var sprit:Sprite = txt.parent as Sprite;
			this.stopDrag();
		}

	}
}